package com.zkrt.upms.common.listener;

import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
import com.github.tocrhz.mqtt.annotation.Payload;
import com.zkrt.upms.service.INotifyRService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MqttListener {

    @Autowired
    private INotifyRService notifyRService;

    /**
     * 物联网推值
     * @param topic
     * @param message
     * @param payload
     */
    @MqttSubscribe("/sys/+/up")
    public void up(final String topic, final MqttMessage message, @Payload final String payload) {
//        log.info("收到消息:"+payload);
//        log.info("\n[订阅主题:消息体] -> \n{} : {}\n", topic, payload);
        notifyRService.saveNotify(topic, payload);
    }

}
